﻿using CID.Domain.Infrastructure;
using CID.Domain.Operations;
using CID.Domain.Users;
using NHibernate;

namespace CID.Domain.Persistence.Tests.Operations
{
    static class DataProvider
    {
        #region ServerRole
        public static ServerRole CreateServerRole(string name = "Server Role Name", string description = "Server Role Description")
        {
            return new ServerRole(name, description);
        }

        public static IServerRole GetServerRole(ISession session, IServerRole serverRoleData)
        {
            return session.Get<ServerRole>(serverRoleData.Id);
        }
        #endregion

        #region Server
        public static Server CreateServer(ISession session, ILocation location, string name = "Server Name", string address = "Server Address")
        {
            return CreateServer(name, address, GetLocation(session, location));
        }

        public static Server CreateServer(string name, string address, ILocation location)
        {
            return new Server(name, address, location);
        }

        public static Server GetServer(ISession session, IServer serverData)
        {
            return session.Get<Server>(serverData.Id);
        }
        #endregion

        #region Environment
        public static Environment CreateEnvironment(ISession session, IUser responsible, string name = "Environment Name", string description = "Environment Description")
        {
            return CreateEnvironment(name, description, Users.DataProvider.GetUser(session, responsible));
        }

        public static Environment CreateEnvironment(string name, string description, IUser responsible)
        {
            return new Environment(name, description, responsible);
        }

        public static Environment GetEnvironment(ISession session, IEnvironment environmentData)
        {
            return session.Get<Environment>(environmentData.Id);
        }
        #endregion

        #region Location
        public static Location CreateLocation(ISession session, IDeploymentAgent deploymentAgent, string name = "Location Name", string description = "Location Description")
        {
            return CreateLocation(name, description, Infrastructure.DataProvider.GetDeploymentAgent(session, deploymentAgent));
        }

        public static Location CreateLocation(string name, string description, IDeploymentAgent deploymentAgent)
        {
            return new Location(name, description, deploymentAgent);
        }

        public static Location GetLocation(ISession session, ILocation locationData)
        {
            return session.Get<Location>(locationData.Id);
        }
        #endregion
    }
}
